"use strict"


function onLogin()
{
    
}

async function getAnnouncement()
{
    $.ajax({
        url: Helper.GetServerIP() + "/getAnnouncement",
                  dataType: "text",
                  type: "post",
                  data: { address:Helper.addressCur },
                  success: async function (data) {
                    var jsonObj = JSON.parse(data);

                    ShowAnnouncement(jsonObj);

                  },
                  error: function (err) {
                    console.log(err);
                  }
    });

}

function ShowAnnouncement(jsonObj){
  var Announcement = $("#Announcement");
  if(Announcement!=undefined){
    // 删除之前的数据
    var mytableEle = Announcement[0];
    for (var i = mytableEle.children.length - 1; i >= 0; i--) {
        mytableEle.children[i].remove();
    }

    var innerHTML = "<div class='d-flex justify-content-center align-items-center pb-5' style='background-color:#1E2335'>\
                    <div class='content-body pt-3' 'style='width: 100%;max-width: 1069px; '>\
                    <div class='container-fluid'>\
                      <div class='center'>\
                        <div style='max-width: 1024px;'>\
                          <h3 class='mt-5'>{title}</h3>\
                          <p>{body}</p>\
                        </div>\
                      </div>\
                    </div>\
                    </div>\
                    </div>";

    var index = 0;
    for (var key in jsonObj) {

        var item = jsonObj[key];

        var html = innerHTML.replace(/{title}/g, item.title  );
        html = html.replace(/{body}/g,  item.body );
        html = html.replace(/#1E2335/g,  index%2==1?"#1E2335":"#111624" );

        var item_new = document.createElement("div");
        item_new.innerHTML = html;
        $(item_new).appendTo( $(Announcement) );

        index++;
    }


  }

}


(function($) {
    "use strict"

    getAnnouncement();

})(jQuery);


